<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{messages.Learntrace}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:outputScript library="javaScript" name="d3.v4.js" target="head"/>
            <h:outputScript library="javaScript" name="graphlib-dot.js" target="head"/>
            <h:outputScript library="javaScript" name="dagre-d3.js" target="head"/>
            <h:outputStylesheet library="css" name="dagre.css"/>
            <h:form>
                <h:panelGrid columns="2">
                    <h:selectOneMenu value="#{subjectController.selected}" 
                                     requiredMessage="#{messages.Select}#{messages.Subject}" immediate="true" required="true">
                        <f:selectItem itemLabel="#{messages.Please}#{messages.Select}"  itemValue="null"/>
                        <f:selectItems value="#{subjectController.getSubject4SchoolList(studentController.logined.schoolId)}"/>
                        <f:ajax render="learningTrace learningTraceGrid"/>
                    </h:selectOneMenu>
                </h:panelGrid>

                <hr/>
                <h:panelGroup id="learningTraceGrid">
                    <h:outputLabel value="#{learnTraceController.learntraceString}"/>
                    <h:panelGroup rendered="#{learnTraceController.items.rowCount > 0}">
                        <h:outputText value="#{learnTraceController.pagination.pageFirstItem + 1}..#{learnTraceController.pagination.pageLastItem + 1}/#{learnTraceController.pagination.itemsCount}"/>&nbsp;
                        <h:commandLink action="#{learnTraceController.pageOperation.previous}" value="#{messages.Previous} #{learnTraceController.pagination.pageSize}" rendered="#{learnTraceController.pagination.hasPreviousPage}"/>&nbsp;
                        <h:commandLink action="#{learnTraceController.pageOperation.next}" value="#{messages.Next} #{learnTraceController.pagination.pageSize}" rendered="#{learnTraceController.pagination.hasNextPage}"/>&nbsp;
                        <h:dataTable value="#{learnTraceController.items}" var="lp" 
                                     border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputLabel value="#{messages.Datetime}"/>
                                </f:facet>
                                <h:outputLabel value="#{publicFields.getDateExpression(lp.createDate)}"/>
                            </h:column>
                            <h:column>
                                <f:facet name="header">
                                    <h:outputLabel value="#{messages.Leadpoint}"/>
                                </f:facet>
                                <h:outputLabel value="#{learnTraceController.getName4KnowledgeListFromLeadpoint(lp)}"/>
                            </h:column>
                        </h:dataTable>
                    </h:panelGroup>
                </h:panelGroup>
                <h:inputHidden id="inputGraph" value="#{learnTraceController.drawCurStudentLeadpoints(studentController.logined)}"/>

                <h:panelGroup id="learningTrace">

                    <svg width="960" height="600"> <g/></svg>
                    <script>
                        var svg = d3.select("svg"),
                                inner = d3.select("svg g"),
                                zoom = d3.zoom().on("zoom", function () {
                            inner.attr("transform", d3.event.transform);
                        });
                        svg.call(zoom);

                        // Create and configure the renderer
                        var render = dagreD3.render();

                        var g;

                        var inputGraph = document.querySelector("#inputGraph");
                        try {
                            g = graphlibDot.read(inputGraph.value);
                        } catch (e) {
                            inputGraph.setAttribute("class", "error");
                            throw e;
                        }

                        g.graph().transition = function (selection) {
                            return selection.transition().duration(500);
                        };

                        // Render the graph into svg g
                        d3.select("svg g").call(render, g);
                    </script>
                </h:panelGroup>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
